package com.axxy.observer;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author 一缕茜阳
 * @date 2021/7/15
 */
public class News extends Subject {

    private List<Observer> observerList = new ArrayList<>();
    private String todayDate;

    @Override
    void getSubject() {
        super.subjectName = "news";
        super.getSubject();
    }

    @Override
    void register(Observer observer) {
        observerList.add(observer);
    }

    @Override
    void remove(Observer observer) {
        observerList.remove(observer);
    }

    @Override
    void notifyObservers() {
        for (Observer o :
                observerList) {
            o.getNewData(todayDate);
            o.operateData();
        }
    }

    void newsChange(){
        this.todayDate = new Date().toString();
    }
}
